package com.sk.skplanet.commute.layouts;

import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout.LayoutParams;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.Actions;
import com.sk.skplanet.commute.vo.Data;

public class ViewLayout {
	public static EditText createEditText(Context context, int type, Integer hintResourceId) {
		EditText editText = new EditText(context);
		editText.setTextColor(Color.parseColor(Data.textview_pointColor));
		editText.setTextSize((float) Actions.DPFromPixel(13));
		editText.setSingleLine();
		LayoutParams layoutParams_editText = new LayoutParams(LayoutParams.MATCH_PARENT, Actions.DPFromPixel(60));
		layoutParams_editText.setMargins(0, 0, 0, Actions.DPFromPixel(5));
		editText.setMinHeight(Actions.DPFromPixel(60));
		editText.setLayoutParams(layoutParams_editText);

		editText.setBackgroundResource(R.drawable.edit_bg);

		if (hintResourceId != null) editText.setHint(hintResourceId);
		if (type == Data.EDITTEXT_SEARCH) editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

		return editText;
	}

	public static Button createButton(Context context, int text) {
		Button button = new Button(context);

		button.setText(text);
		button.setTextColor(Color.parseColor(Data.textview_dialogTitle));
		button.setBackgroundResource(R.drawable.btn_01_nor);
		button.setTextSize((float) Actions.DPFromPixel(12));
		{
			android.view.ViewGroup.LayoutParams layoutParams_button = new LayoutParams(LayoutParams.MATCH_PARENT,
					Actions.DPFromPixel(60), 1);
			button.setLayoutParams(layoutParams_button);
		}

		button.setOnTouchListener(new OnTouchListener() { // 버튼 터치시 이벤트
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) // 버튼을 누르고 있을 때
				v.setBackgroundResource(R.drawable.btn_01_tch);
				if (event.getAction() == MotionEvent.ACTION_UP) { // 버튼에서 손을 떼었을 때
					v.setBackgroundResource(R.drawable.btn_01_nor);
				}
				return false;
			}
		});
		return button;
	}

}
